<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class OrderController extends Controller
{
    //
    public function Index(Request $request)
    {
    	// dd($request->all());
    	$goods = session('cart');
        //从session查询用户id
        $user = session('user');
        // dd($user->userId);
        $address = DB::table('storeaddress')->where('uid',$user->userId)->get();
        // dd($address);
    	// dd($goods);
    	$data = [];
    	foreach($goods as $k=>$v){
    		$tem = DB::table('goodsmain')->where('id',$v['id'])->first();
    		$tem->num = $v['num'];
    		$data[]=$tem;
    	}
    	// dd($data);

    	$jiage = [];
    	foreach($data as $k=>$v){
    		if(empty($v->price)){
    			$jiage[]=$v->hwprice * $v->num;
    		}else{
    			$jiage[]=$v->price * $v->num;
    		}
    		
    	}
    	// dd($jiage);
    	$zongjia = '';
    	foreach($jiage as $v){
    		$zongjia+=$v;
    	}
        
    	// dd($zongjia);
    	return view('home.querendingdan',['data'=>$data,'zongjia'=>$zongjia,'address'=>$address]);
	}
    	
    
}
